package com.evendai.sipdemo

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.evendai.sipdemo.databinding.ActivityBaseBinding
import com.evendai.sipdemo.util.ActivityUtil
import com.evendai.sipdemo.util.DialogUtil

/** Activity的基类，其它Activity应该继承此类 */
abstract class BaseActivity : AppCompatActivity(), UiOperation {

    private val binding: ActivityBaseBinding by lazy { ActivityBaseBinding.inflate(layoutInflater) }

    /** 用于指定当前界面是否可以在按返回时返回到上一个界面 */
    @Suppress("MemberVisibilityCanBePrivate")
    protected var cancellable: Boolean = true

    override fun onCreate(savedInstanceState: Bundle?) {
//        requestWindowFeature(Window.FEATURE_NO_TITLE)
//        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
        super.onCreate(savedInstanceState)
        ActivityUtil.addActivity(this)
        setContentView(binding.root)
        initView()
        initListener()
        initData()
    }

    protected fun getContentContainer() = binding.flContent

    override fun onDestroy() {
        super.onDestroy()
        ActivityUtil.removeActivity(this)
    }

    fun setLoadingText(text: CharSequence) {
        binding.tvLoading.text = text
    }

    fun showLoading() {
        binding.llLoading.visibility = View.VISIBLE
    }

    fun hideLoading() {
        binding.llLoading.visibility = View.GONE
    }

    fun showOneButtonDialog(msg: String, title: String = getString(R.string.tip), confirmButtonDesc: String = getString(android.R.string.yes), onClickConfirmButton: (()->Unit)? = null) = DialogUtil.showDialog(this, msg, title, confirmButtonDesc, onClickConfirmButton)
    fun showTwoButtonDialog(msg: String, title: String = getString(R.string.tip), confirmButtonDesc: String = getString(R.string.confirm), onClickConfirmButton: (()->Unit)? = null, cancelButtonDesc: String = getString(R.string.cancel), onClickCancelButton: (()->Unit)? = null) = DialogUtil.showDialog(this, msg, title, confirmButtonDesc, onClickConfirmButton, cancelButtonDesc, onClickCancelButton)

    override fun onBackPressed() {
        if (cancellable || binding.llLoading.visibility != View.VISIBLE) {
            super.onBackPressed()
        }
    }

}
